const Utils = require("./Utils.js")

Utils.init()

// 关闭好友协助申请
threads.start(() => {
  while (true) {
    sleep(30 * 1000)
    Utils.findPhotoTap("叉号", 0.8, [1100, 120, 140, 120])
  }
})

var flag, num, count, times, storage

storage = storages.create("yys")
num = 0 // 检查挖土
count = 0 // 挖土次数
times = storage.get("wt_num") || 120 // 计划挖土次数
flag = true

while (flag) {
  Utils.sleeps()
  if (Utils.findPictureTap("挑战挖土", 0.98)) {
    let seconds = 40
    Utils.waitTime(seconds)
    let flagTemoOne = true
    while (flagTemoOne) {
      Utils.sleeps()
      if (Utils.findPictureTap("奖励") || Utils.findPictureTap("奖励2")) {
        log("已挖土 " + ++count + " 次")
        flagTemoOne = false
      } else if (Utils.findPictureTap("胜利")) {
      } else if (Utils.findPictureTap("失败")) {
        Utils.sleeps()
        Utils.tapPicture("确定")
        flagTemoOne = false
      }
      log("已等待：" + ++seconds + "秒")
    }
    num = 0
  }
  num++
  log("检查挖土第 " + num + "次")
  num === 100 ? Utils.stopJB() : ""
  count == times ? (log("已成功挖土 " + count + " 次"), Utils.stopJB()) : ""
}
